package com.sxt.bus.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.bus.domain.Goods;
import com.sxt.bus.domain.Inport;
import com.sxt.bus.mapper.GoodsMapper;
import com.sxt.bus.mapper.InportMapper;
import com.sxt.bus.service.GoodsService;
import com.sxt.bus.service.InportService;
import com.sxt.bus.vo.GoodsVo;
import com.sxt.bus.vo.InportVo;
import com.sxt.bus.utils.DataGridView;
@Service
public class InportServiceImpl implements InportService{

	@Autowired
	private InportMapper inportMapper;
	
	@Autowired
	private GoodsMapper goodsMapper;
	
	@Override
	public DataGridView queryAllInport(InportVo inportVo) {
		Page<Object> page = PageHelper.startPage(inportVo.getPage(),inportVo.getLimit());
		List<Inport> data = inportMapper.queryAllInport(inportVo);
		return new DataGridView(page.getTotal(),data);
	}

	@Override
	public Integer updateInport(InportVo inportVo) {
		// TODO Auto-generated method stub
		return inportMapper.updateByPrimaryKeySelective(inportVo);
	}

	@Override
	public void addInport(InportVo inportVo) {
		// TODO Auto-generated method stub
		inportMapper.insertSelective(inportVo);
		Goods goods = goodsMapper.selectByPrimaryKey(inportVo.getGoodsid());
		goods.setNumber(inportVo.getNumber()+goods.getNumber());
		goodsMapper.updateByPrimaryKeySelective(goods);
	}

	@Override
	public void deleteInport(Integer id) {
		Inport inport = inportMapper.selectByPrimaryKey(id);
		inportMapper.deleteByPrimaryKey(id);
		
		Goods goods = goodsMapper.selectByPrimaryKey(inport.getGoodsid());
		goods.setNumber(goods.getNumber()-inport.getNumber());
		
		goodsMapper.updateByPrimaryKeySelective(goods);
	}

	

}
